package cn.dlc.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.dlc.com.config.Config;
import cn.dlc.com.config.ConfigCenter;
import cn.dlc.com.model.User;
import cn.dlc.com.property.ZookeeperProperty;
import cn.dlc.com.service.UserService;

@RestController
@RequestMapping("user")
@EnableConfigurationProperties(ZookeeperProperty.class)
public class UserController {
	
	@Autowired
	private UserService configservice;
	
	@Autowired
	private ConfigCenter configCenter;
	
	@Autowired
	private ZookeeperProperty zk;

	@GetMapping("{id}")
	public User user(@PathVariable("id") String id) throws Exception{
		User user = configservice.getUserById(id);
		// 获取最新的配置信息
		Config config = configCenter.getConfig(zk.getUrl(), zk.getNodePath());
		System.out.println("新的：" + config.getDbUrl());
		System.out.println("新的：" + config.getDbUrl());
		System.out.println("新的：" + config.getDbUrl());
		return user;
	}
	
	
}
